package com.mjk.common.web.getway.utils.loadbalancer.impl;

import com.mjk.common.web.getway.utils.loadbalancer.AbstractLoadBalancer;

import java.util.List;
import java.util.Random;

/**
 * 静态负载均衡示例算法：随机
 */
public class RandomLoadBalance extends AbstractLoadBalancer {
    private Random random;

    public RandomLoadBalance() {
        random = new Random();
    }

    public String getNextServer(String key) {
        int index = random.nextInt(servers.size());
        return servers.get(index).get(index);
    }
}
